package com.yowasa.xiuxian.engine.battle.strategy.skill.soild;

import com.yowasa.xiuxian.annoations.BS;
import com.yowasa.xiuxian.constant.XiuxianConstants;
import com.yowasa.xiuxian.engine.battle.strategy.BaseDefendStrategy;
import com.yowasa.xiuxian.engine.battle.strategy.BattleStrategy;
import com.yowasa.xiuxian.entity.bo.battle.BattleContent;
import com.yowasa.xiuxian.entity.bo.battle.UserBattleContent;
import com.yowasa.xiuxian.entity.bo.user.UserBO;
import com.yowasa.xiuxian.entity.bo.user.UserBattle;
import com.yowasa.xiuxian.entity.enums.ElementEnum;
import com.yowasa.xiuxian.entity.enums.StageEnum;
import com.yowasa.xiuxian.exception.HandlerException;
import com.yowasa.xiuxian.service.helper.BattleHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

@BS(name = "万钧甲", upAbility = 4, needTravel = 1000)
@Order(2)
@Component
public class WanJunJia extends BaseDefendStrategy {

    @Autowired
    private BattleHelper battleHelper;

    @Override
    public ElementEnum getElement() {
        return ElementEnum.SOIL;
    }

    @Override
    public void limit(UserBO user) {
        if (user.getElement().get("土") < XiuxianConstants.DEFAULT_ELEMENT_ACTIVITY) {
            throw new HandlerException("学习/使用万钧甲必须具有土灵根");
        }
        if (user.getStage() < StageEnum.ZHU_JI.getLevel()) {
            throw new HandlerException("学习/使用万钧甲至少要始明之青");
        }
    }
    @Override
    public String limitDesc() {
        return "达到始明之青且具有土灵根";
    }

    @Override
    public String desc() {
        return "对方对你造成伤害后增加自身15%的物理防御,在护甲超过原本护甲两倍后消耗0.1护甲值的MP在受伤结算前对对手造成以自己护甲为攻击力计算的物理伤害（不触发对方防御特性）";
    }

    @Override
    public int defend(UserBattleContent user, UserBattleContent battleUser, BattleStrategy bs, int dmg, BattleContent content) {
        UserBattle tempBattleInfo = user.getTempBattleInfo();
        int addDef = user.getUserBO().getUserBattle().getDef() / 7;
        tempBattleInfo.setDef(1 + tempBattleInfo.getDef() + addDef);
        user.getBattleInfo().setDef(user.getBattleInfo().getDef() + addDef);
        if (tempBattleInfo.getDef() / user.getUserBO().getUserBattle().getDef() >= 2) {
            int costMp = user.getBattleInfo().getDef() / 10;
            if (user.getBattleInfo().getCmp() >= costMp) {
                user.getBattleInfo().setCmp(user.getBattleInfo().getCmp() - costMp);
                int atk = user.getBattleInfo().getDef();
                int tDmg = battleHelper.calAtk(atk, tempBattleInfo.getDef());
                battleUser.getBattleInfo().setChp(battleUser.getBattleInfo().getChp() - tDmg);
                content.getMsgLog().add(battleUser.getUserBO().getName() + "因对手万钧甲效果损失" + tDmg + "点血量");
            }
        }
        return dmg;
    }


    @Override
    public boolean check(UserBattleContent user, BattleStrategy bs, BattleContent content) {
        return true;
    }


}
